<?php
// $Id$

/**
 * Controller_Cashback 控制器
 */
class Controller_Cashback extends Controller_Abstract
{

	function actionIndex()
	{
        // 为 $this->_view 指定的值将会传递数据到视图中
		# $this->_view['text'] = 'Hello!';
	}
	
	function actionSave(){
		
		
		if($this->_context->isPOST()){
			$user = $this->_app->currentUser();
			
			try {
				foreach($_POST['amount'] as $key => $val){
					$_POST['user_id'] = $user['id'];
					$_POST['member_id'] = $key;
					$_POST['amount'] = $val;
					if($val){
						$cashback = new Cashback($_POST);
						$cashback->save();
					}
				
				}
				
					
				return json_encode(array('success'=>'ok'));
			}
			catch (QDB_ActiveRecord_ValidateFailedException $e){
				return json_encode(array('errorMsg' => $e->getMessage()));
			}
			catch (QDB_Exception $e){
				return json_encode(array('errorMsg' => $e->getMessage()));
			}
		}
		
		
	}
	
	
	
}


